from OpenGL.GL import *
from common.util import bind_texture
import numpy
import pyglet
import Image

from common import *
from md2.structures import MD2Model
from util import file_path
from GLUtil.camera import Camera
from GLUtil.lighting import Lighting

class Manager(object):
	"""
	This is the base class for all managers.
	It was designed to be a static class, such that it 
	should be possible be accessible from anywhere.
	"""
	
	# Constants
	MODELS_FOLDER = '../data/models/'
	TEXTURES_FOLDER = '../data/textures/'
	
	# Attributes
	map = None
	camera = Camera()
	lighting = Lighting()
	models = {}
	textures = {}
	
	@staticmethod
	def initialize(map):
		Manager.map = map
	
	@staticmethod
	def load_models():
		print 'Loading textures...',
		Manager.__load_texture(Manager.TEXTURES_FOLDER + 'squares.png', 'squares')
		print 'Done!' 
		
		print 'Loading models...',
		#Manager.__load_model(Manager.MODELS_FOLDER, 'fuel')
		Manager.__load_model(Manager.MODELS_FOLDER, 'tekkblade')
		print 'Done!'
	
	@staticmethod
	def __load_model(folder, name):
		path = folder + name + '/'
		
		model = MD2Model()
		tex_blue = bind_texture(path + 'blue.pcx')
		tex_yellow = bind_texture(path + 'yellow.pcx')
		
		model.load(file_path(path + 'tris.md2'), tex_blue, tex_yellow)
		Manager.models[name] = model
		
	@staticmethod
	def __load_texture(path, name):
		Manager.textures[name] = bind_texture(path)
	
	#@staticmethod
	def __init__(self):
		"""
		Since this is a static class, this method should never be called.
		"""
		
		raise Exception("Manager instance summoned!") 